package com.example.springboot_c.Controller;

import com.example.springboot_c.Service.ProductCategoryService;
import com.example.springboot_c.pojo.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/category")
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService categoryService;

    @GetMapping("/list")
    public String list(Model model) {
        model.addAttribute("categories", categoryService.findAll());
        return "category_list";
    }

    @PostMapping("/add")
    public String add(ProductCategory category) {
        categoryService.insert(category);
        return "redirect:/category/list";
    }
}